package com.shenmazg6.sentinel.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 军哥
 * @version 1.0
 * @description: AntiController
 * @date 2022/12/28 13:52
 */

@RestController
@Slf4j
@RequestMapping(value = "/anti")
public class AntiController {

    @GetMapping(value = "/helloWorld2")
    @SentinelResource(value = "helloWorld2", blockHandler = "blockHandler")
    public String helloWorld2() {
        String msg = "helloWorld2:" + System.currentTimeMillis();
        log.info(msg);

        return msg;
    }

    public String blockHandler(BlockException ex) {

        ex.printStackTrace();

        log.error("blockHandler:系统繁忙," + System.currentTimeMillis());
        return "系统繁忙，请稍后再试......";
    }

}
